<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app"></div>

  <template id="my-app">
    <h2>当前温度：{{temp}}</h2>
    <h3>建议穿：{{cloth}}</h3>

    <button @click="minus">-5</button>
    <button @click="add">+5</button>

  </template>


  <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.3.4/vue.global.js"></script>
  <script>
    Vue.createApp({
      template: '#my-app',
      data() {
        return {
          temp: 20,
          // cloth: '夹克'
        }
      },
      computed: { // 计算属性是响应式执行的
        cloth() { // 函数会在所依赖的变量值发生改变时自动重新执行
          if (this.temp <= 10) {
            return  '棉袄'
          } else if (this.temp <= 20) {
            return '夹克'
          } else {
            return '短袖'
          }
        }
      },
      methods: {
        minus() {
          this.temp -= 5
          // if (this.temp <= 10) {
          //   this.cloth = '棉袄'
          // } else if (this.temp <= 20) {
          //   this.cloth = '夹克'
          // } else {
          //   this.cloth = '短袖'
          // }
        },
        add() {
          this.temp += 5
        }
      }
    }).mount('#app')
  </script>
</body>
</html>